package leetcode.动态规划.middle;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author wangmaolin1
 * @date 2023/11/14 00:30
 */
public class _139 {
    public static boolean wordBreak(String s, List<String> wordDict) {
        Set<String>set=new HashSet<>(wordDict);
        boolean[]dp=new boolean[s.length()+1];
        dp[0]=true;
        for (int i = 1; i <= s.length(); i++) {
            for (int j = 0; j < i; j++) {
                if (dp[j] && set.contains(s.substring(j,i))){
                    dp[i]=true;
                    break;
                }
            }
        }
        return dp[s.length()];
    }

    public static void main(String[] args) {
        ArrayList<String> objects = new ArrayList<>();
        objects.add("leet");
        objects.add("code");
        System.out.println(wordBreak("leetcode",objects));
    }
}
